//
//  ModelSets.swift
//  Order
//
//  Created by Lazyloading on 2020/7/2.
//  Copyright © 2020 lazyloading. All rights reserved.
//

import Foundation

let kUserInfo = "kUserInfo";
fileprivate let filePath = NSHomeDirectory() + "/Documents/contacts.data"

//MARK: 🐷 业务model 🐷
class UserinfoModel: BaseModel{
   
    var token: String!
    var loginTime : String?

    //存储
    func save(){
        self.loginTime = Date().timeStamp;
        do {
            let jsonData = try JSONSerialization.data(withJSONObject: self.toJSON() as Any, options: [])
            let json = String(data: jsonData, encoding: .utf8) ?? "";
            UserDefaults.standard.set(json, forKey: kUserInfo);
        } catch  {}
    }
    
    //获取
    static func getInfo() -> UserinfoModel?{
        let json = UserDefaults.standard.value(forKey: kUserInfo) as? String;
        if json == nil{
            return nil;
        }else{
            return UserinfoModel.deserialize(from: json);
        }
    }
}

///银行卡列表
class BankListModel: BaseModel {
    var cardName : String?
    var cardNum : String?
    var id : String?
}

///二维码列表
class QRCodeListModel: BaseModel {
    var account : String?
    var methodName : String?
    var qrcodeUrl = ""
    var id : String?
    
    func codeImgUrl()  -> String{
        return baseUrl + self.qrcodeUrl;
    }
    
}

///首页公告
class NoticeModel: BaseModel {
    var content : String?
    var title : String?
    var status : String?
}

///列表模型
class OrderListModel: BaseModel {
    
    var createTime : String?
    var orderId : String?
    var orderPrice : String?
    var orderStatus : String?
    var paymentMethod : String?
    var rebate : String?
    var receiverId : String?
    var updateTime : String?
    
    
    func typeDesc()  -> String?{
        var str : String?
        if paymentMethod?.int() == 1{
            str = "微信";
        }else if paymentMethod?.int() == 2{
            str = "支付宝";
        }else{
            str = "银行卡";
        }
        return str;
    }
}

///首页公告
class OrderDetailModel: BaseModel {
    
    var commitTime : String?
    var orderId : String?
    var orderPrice : String?
    var orderStatus : String?
    var paymentMethod : String?
    var rebate : String?
    var receiverId : String?
    var updateTime : String?
    
    func statusDesc()  -> String?{

        switch orderStatus?.int() {
        case 0:
            
            return "未接单"
            
        case 1:
            
            return "已抢单未扣款"
            
        case 2:
            
            return "已扣款未返点"
            
        case 3:
            
            return "已完成"
            
        default:
            return "未知";
        }
        
    }
    
    func typeDesc()  -> String?{
        return self.paymentMethod;
//        var str : String?
//        
//        if paymentMethod?.int() == 1{
//            str = "微信";
//        }else if paymentMethod?.int() == 2{
//            str = "支付宝";
//        }else{
//            str = "银行卡";
//        }
//        return str;
    }
    
    
    
    
}
